import { getPendingList, getquestionHandle, getQuestionsAllList } from '@/services/modules/questionHandle';
import { IParamsItem, questionHandleItem, questionHandleListItem } from '@/utils/questionHandle';
import { makeAutoObservable } from 'mobx';

class Handle {
    constructor() {
        makeAutoObservable(this)
    };
    //评论数量小图标
    xx: string = ""

    //分页
    pageNum: number = 1
    setPageNum(e: number) {
        this.pageNum = e
    }

    //类型状态
    status = ""
    setStatus(type: string) {
        this.status = type
    }

    //模糊搜索
    title = ""
    questionTitle = ""
    setTitle(e: string) {
        this.title = e
    }
    setQuestionTitle(title: string) {
        this.questionTitle = title
    }


    //全选 
    checkedAll: boolean = false
    setCheckedAll(e: boolean) {
        this.checkedAll = !this.checkedAll
        this.questionHandleList.map((item) => {
            return item.flag = this.checkedAll
        })
    }
    //反选

    setCheckedItem(i: number) {
        this.questionHandleList[i].flag = !this.questionHandleList[i].flag
        this.checkedAll = this.questionHandleList.every(item => item.flag)
    }

    // //取消精品
    // async setdeleteQuality(params: string) {
    //     let res = await getdeleteQuality(params)
    //     console.log("取消成功", res)
    // }

    // //设置精品
    // async getanswerQuality(params: string) {
    //     let res = await getanswerQuality(params)
    //     console.log("设置成功", res)
    // }
    // //取消屏蔽
    // async getdeleteShield(params: string) {
    //     let res = await getdeleteShield(params)
    //     console.log("取消屏蔽成功", res)
    // }
    // //设置屏蔽 getanswerShield
    // async getanswerShield(params: string) {
    //     let res = await getanswerShield(params)
    // }
    //数据来源 网站2021A班questionHandleItem
    questionHandle: questionHandleItem[] = []
    async getquestionHandle() {
        let res = await getquestionHandle()
        if (res.data) {
            this.questionHandle = res.data
        }
    }


    //所有待回答数据列表
    pendingList: questionHandleListItem[] = []
    //数据列表的长度
    pendingListLen: number = 0
    async getPendingList(params: IParamsItem) {
        let res = await getPendingList(params)
        if (res.rows) {
            this.pendingList = res.rows
            this.pendingListLen = res.total
        }
    }

    // 所有回答数据列表
    questionHandleList: questionHandleListItem[] = []
    //数据列表的长度
    questionListLen: number = 0
    async getQuestionsAllList(params: IParamsItem) {
        let res = await getQuestionsAllList(params)
        if (res.rows) {
            this.questionHandleList = res.rows.map((item: { flag: boolean; }) => {
                item.flag = false
                return item
            })
            this.questionListLen = res.total
        }
    }
}

export default new Handle